package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecurityquery;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.commom.factory.ReturnFactory;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.CommandTypeContext;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandType;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.SubCommandHandler;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecurityquery.activeresourcemonitorquery.ActiveResourceMonitorQueryImpl;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecurityquery.illegalmanagementexecutionrecord.IllegalManagementExecutionRecordImpl;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hasee on 2019/2/21.
 * 信息安全查询指令
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class InfoSecurityQueryImpl implements CommandType {

    private static final int num = 6;

    @Autowired
    private ActiveResourceMonitorQueryImpl activeResourceMonitorQuery;
    @Autowired
    private IllegalManagementExecutionRecordImpl illegalManagementExecutionRecord;

    private List<SubCommandHandler> subCommandHandlerList;

    @PostConstruct
    public void init(){
        subCommandHandlerList = new ArrayList<>();
        subCommandHandlerList.add(activeResourceMonitorQuery);
        subCommandHandlerList.add(illegalManagementExecutionRecord);
    }

    @Override
    public boolean isMatch(Option option) {
        return option.getType() == num;
    }

    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        for(SubCommandHandler handler : subCommandHandlerList){
            if(handler.isMatch(xmlData)){
                return handler.execute(xmlData, commandModel);
            }
        }
        return ReturnFactory.getFormatExceptionReturn("没有相关指令服务，调用结束,请检验指令内容格式是否存在问题");
    }
}
